package com.cop4331.social;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

/**
 * 
 * @author Matt Szoke
 * @LastUpdated: 4/12/2012 by Matt Szoke
 * 
 * Adapter
 * 
 */
public class SpecialAdapter extends SimpleAdapter {

	Context context;
	
	// -----------------------------------------------
	// CONSTRUCTOR
	// -----------------------------------------------
	public SpecialAdapter(Context context, List<Map<String, Object>> items,
			int resource, String[] from, int[] to) {
		super(context, items, resource, from, to);
		this.context = context;
	}

	// -----------------------------------------------
	// GETVIEW
	// -----------------------------------------------
	public View getView(int position, View convertView, ViewGroup parent) {

		DatabaseHandler db = new DatabaseHandler(this.context);
		HashMap<String, String> user = db.getUserDetails();
		String un = user.get("name");

		View view = super.getView(position, convertView, parent);

		@SuppressWarnings("unchecked")
		Map<String, Object> item = (Map<String, Object>) this.getItem(position);

		System.out.println(item);
		
		// If tutor request for you, set to color green, else black
		if (item.get("tutor").toString().compareTo(un) == 0)
			view.setBackgroundColor(Color.parseColor("#148900"));
		else
			view.setBackgroundColor(Color.BLACK);

		return view;
	}

}
